#include <stdio.h>
#include <string.h>

#define NMAX 100000
#define MAX_COMMAND_LEN 10


int map[2][NMAX];

struct node {
	int value;
	int index;
}

struct heap {
	struct node array[NMAX];
	int size = 0;
	signed char sgn;
		/*
		 *  1 -- max
		 * -1 -- min
		 *  0 -- ???
		 */

	struct node Extract_top(const char* s)
	{
		struct node ret;
		ret = array[0];
		--size;
		array[0] = array[size];
		Heap_sort__sift_down(0, size);
		return ret;
	}
	void remove_elem__index(int
}

int
main(void)
{
	struct heap minheap[NMAX];
	struct heap maxheap[NMAX];
	int i = 0;
	char line[MAX_COMMAND_LEN+1];

	(void) freopen("minimax.in", "r", stdin);
	(void) freopen("minimax.out", "w", stdout);

	scanf("%d\n", &n);
	while (i < n) {
		(void) fgets(line, MAX_COMMAND_LEN, stdin);
		if (!strcmp(line, "ExtractMax\n"))
			printf("%d\n", ExtractMax(array, a_size--));
		else if (!strcmp(line, "ExtractMin\n"))
			printf("%d\n", ExtractMin(rev_heap, a_size--));
		else {
			(void) sscanf(line, "Insert(%d)\n", &to_add);
			insert(array, rev_heap, ++a_size, to_add);
		}
		++i;
	}
	return 0;
}
